package com.kt.opc.service.impl;

import com.kt.opc.po.Node;
import com.kt.opc.po.Station;
import com.kt.opc.service.OpcService;
import com.kt.opc.util.OpcPool;
import com.kt.opc.util.OpcUtil;
import org.eclipse.milo.opcua.sdk.client.OpcUaClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OpcServiceImpl  implements OpcService{
    private final Logger logger = LoggerFactory.getLogger(getClass()); //日志


   // public void


    @Override
    public void conStation(Station station) {

        try {

            logger.info("连接OPC："+station.getIp());
            OpcUaClient opcUaClient=   OpcUtil.createClient("opc.tcp://" + station.getIp(),station.getUsername(),station.getPassword());
            OpcPool.inPool(station.getId(),opcUaClient); //入连接池
            logger.info("连接OPC成功");

        } catch (Exception e) {

            logger.info("连接OPC失败");
            e.printStackTrace();
        }


    }
}
